<?php

namespace App\Admin\Forms;

use App\Models\User;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Response;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Contracts\LazyRenderable;

class TimeClass extends Form implements LazyRenderable
{
    use LazyWidget;
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return Response
     */
    public function handle(array $input)
    {
        // dump($input);
        // 获取外部传递参数
        $class_end_time = $input['class_end_time'] ?? null;
        if (!$class_end_time){
            return $this->error('时间不能为空', '/User');
        }
        $user_id = $this->payload['id'] ?? null;
        //查询此人身份
        $level = User::where('id',$user_id)->value('level');
        if ($level != 1){
            return $this->error('此人不是球员', '/User');
        }
        //更新
        $res = User::where('id',$user_id)->update(['class_end_time'=>strtotime($class_end_time)]);
        if ($res){
            return $this->success('修改成功', '/User');
        }else{
            return $this->error('修改失败', '/User');
        }
    }
    /**
     * Build a form here.
     */
    public function form()
    {
        $this->datetime('class_end_time','合同时间');
    }

}
